//
//  Grouping.swift
//  SwiftUIFly
//
//  Created by shen on 2023/10/18.
//

import SwiftUI

struct Grouping<Content: View>: View {
    var title: String
    var icon: String
    var content: () -> Content

    var body: some View {
        NavigationLink {
            GroupView(title: title, content: content)
        } label: {
            Label {
                Text(title)
            } icon: {
                Image(systemName: icon)
            }
            #if os(iOS)
            .font(.headline)
            .padding(.vertical, 8)
            #endif
        }
    }
}

struct GroupView<Content: View>: View {
    var title: String
    let content: () -> Content

    var body: some View {
        #if os(iOS)
        return List {
            content()
        }
        .listStyle(InsetGroupedListStyle())
        .navigationBarTitle(title, displayMode: .inline)
        #else
        return ScrollView {
            content().padding()
        }.frame(maxWidth: .infinity, maxHeight: .infinity)
        #endif
    }
}
